<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'adminList.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<!--框架必需start-->
<script type="text/javascript" src="ui/js/jquery.js"></script>
<script type="text/javascript" src="ui/js/framework.js"></script>
<script type="text/javascript" src="ui/js/Validform_v5.3.2.js"></script>
<link href="ui/css/import_basic.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" id="skin" prePath="/"/>
<link rel="stylesheet" type="text/css" id="customSkin"/>
<link href="ui/skins/blue/style.css" rel="stylesheet" type="text/css" id="theme" themeColor="blue"/>
<!--框架必需end-->

  <body>
 
	<div class="box2" panelTitle="添加用户" style="margin-left: auto;margin-right: auto;float: left;width: 100%;">
		<fieldset>
			<form action="adminAdd.action" method="post" class="registerform">
		<table class="tableStyle" formMode="transparent" >
			<tr>
				<td>管理员账号:</td>
				<td><input type="text" id="adminName" name="admin.adminName" datatype="s6-18" errormsg="名称至少6个字符,最多18个字符！"/></td>
				<td><div class="Validform_checktip"></div></td>				
			</tr>
			<tr>	
				<td>管理员密码:</td>
				<td><input type="password" id="password" name="admin.password" datatype="*6-15" errormsg="密码范围在6~15位之间！"/></td>
				<td><div class="Validform_checktip"></div></td>			
			</tr>	
			<tr>	
				<td>重复管理员密码:</td>
				<td><input type="password" id="repassword" name="repassword" datatype="*" recheck="admin.password" errormsg="您两次输入的账号密码不一致！"/></td>
				<td><div class="Validform_checktip"></div></td>			
			</tr>	
			<tr>
				<td>电子邮箱:</td>
				<td><input type="text" id="email" name="admin.email" datatype="e" errormsg="邮箱格式有误！"/></td>
				<td><div class="Validform_checktip"></div></td>				
			</tr>
			<tr>	
				<td>电话:</td>
				<td><input type="text" id="phone" name="admin.phoneNumber" datatype="m" errormsg="请输入11位移动电话号码！"/></td>
				<td><div class="Validform_checktip"></div></td>
			</tr>	
			<tr>	
				<td>权限:</td>
				<td>
					<select id="role" keepDefaultStyle="true" name="admin.roles" onchange="select();">
						<option value="1">超级管理员</option>
						<option value="2" selected="selected">普通管理员</option>
					</select>
				</td>
			</tr>
			<tr id="ms">	
				<td>管理站:</td>
								<td>
									<select id="sel-15" keepDefaultStyle="true" name="admin.managementStation.MSId" >
										<s:iterator value="stations" var="st">
											 <option value="<s:property value="#st.MSId"/>">
											 	<s:property value="#st.MSName"/>
											 </option>
										</s:iterator>
									</select>
								</td>
			</tr>
			<tr>
				<td>
					<input type="submit" value="注册"/>
				</td>
				<td>
					<input type="reset" value=" 重 置 "/>
				</td>
			</tr>
		</table>
		</form>
		 </fieldset>
	</div>	
	
	<div id="scrollContent" style="float: left;width: 100%">
	<table class="tableStyle" useClick="false" id="list" style="text-align: center;">
			<tr>
				<th width="5%">编号</th>
				<th width="10%">管理员账号</th>
				<th width="10%">管理员密码</th>
				<th width="20%">电子邮箱</th>
				<th width="15%">电话号码</th>
				<th width="10%">管理权限</th>
				<th width="15%">管理站</th>
				<th width="5%">激活</th>
				<th width="10%">操作</th>
			</tr>
			
			<s:iterator value="adminList"  var="al">
				<tr>
				<td><s:property value="#al.id"/></td>
				<td><s:property value="#al.adminName"/></td>
				<td><s:property value="#al.password"/></td>
				<td><s:property value="#al.email"/></td>
				<td><s:property value="#al.phoneNumber"/></td>
				<td>
					<s:set value="#al.roles" name="roles"></s:set>
					<s:if test="roles==1">
						<span>超级管理员</span>
					</s:if>
					<s:else>
						<span>普通管理员</span>
					</s:else>
				</td>
				<td>
					<s:if test="roles==1">
						*
					</s:if>
					<s:else>
						<s:property value="#al.managementStation.MSName"/>
					</s:else>
				</td>
				<td>
				<s:if test="#al.roles==2">
						<s:if test="#al.isEnabled==1">
							<input type="checkbox" class="enable" checked/>
						</s:if>
						<s:else>
							<input type="checkbox" class="enable" name=""/>
						</s:else>
				</s:if>
				<s:else>
					
				</s:else>
				</td>
				<td><span class="img_edit hand" title="修改"></span><span class="img_delete hand"  title="删除"></span></td>
			</tr>
			</s:iterator>		
		</table>	
		
	</div>		
	<s:set value="#addFlag" name="flag"></s:set>
	<s:if test="flag==0">
		111
	</s:if>
	<script>
		var id;
		var adminName;
		var email;
		var phoneNumber;
		var roles;
		var managementStation;
		var $currentTr;
		$(function(){
			$(".img_btn_up").click(function(){
				upHandler($(this));
			});
			$(".img_delete").click(function(){
				delHandler($(this));
			});
			$(".img_edit").click(function(){
				modiHandler($(this));
			});
		});
		//删除行
		function delHandler($obj){
			top.Dialog.confirm("确定要删除吗？",function(){
				id=$obj.parents("tr").find("td").eq(0).html();
				location.href='adminDel.action?adminId='+id;
			});
		}	
		//弹出修改窗口
		/*
		function modiHandler($obj){
			top.Dialog.open({URL:"./admin/adminMod.jsp",Title:"修改",Width:500,Height:240});
			id=$obj.parents("tr").find("td").eq(0).html();
			adminName=$obj.parents("tr").find("td").eq(1).html();
			email=$obj.parents("tr").find("td").eq(2).html();
			phoneNumber=$obj.parents("tr").find("td").eq(3).html();
			roles=$obj.parents("tr").find("td").eq(4).html();
			managementStation = $obj.parents("tr").find("td").eq(5).html();
			$currentTr=$obj.parents("tr");
		}
		*/
		//是否激活账户
		$(".enable").click(function(){
				if($(this).attr("checked")){
					 var params = {
			 	   		adminId:$(this).parents("tr").find("td").eq(0).html(),
		       	   		isEnabled : 1
		       		 };
					 $.ajax({
				    type: "POST",
				    url: "enabled.action",
				    data: params,
				    dataType:"text", //ajax返回值设置为text（json格式也可用它返回，可打印出结果，也可设置成json）
				    success: function(){  
				   	 alert("用户激活成功！");
				    },
				    error: function(){					
				    }
		  		  });
				}else{
					 var params = {
			 	   		adminId:$(this).parents("tr").find("td").eq(0).html(),
		       	   		isEnabled : 0
		       		 };
					$.ajax({
				    type: "POST",
				    url: "enabled.action",
				    data: params,
				    dataType:"text", //ajax返回值设置为text（json格式也可用它返回，可打印出结果，也可设置成json）
				    success: function(){  
				   	 alert("用户注销成功！");
				    },
			    error: function(){
			    }
		    	});
			}
		});
		
		function modiHandler($obj){		
			var adminId=$obj.parents("tr").find("td").eq(0).html();
		   //	var taskKind=$obj.parents("tr").find("td").eq(1).html(); 
			//$("#lineChart").src='jfreechart.action?taskId='+taskId+'&taskKind='+taskKind;
			//$("#lineChart").location.reload();
			location.href='getAdminById.action?adminId='+adminId;
		}			
		/**
		function openwin($obj){ 
			var answer=window.showModalDialog("sample/table/AdminMod.jsp",window.top,"dialogWidth:500px;dialogHeight:240px:center:yes"); 
			id=$obj.parents("tr").find("td").eq(0).html();
			adminName=$obj.parents("tr").find("td").eq(1).html();
			email=$obj.parents("tr").find("td").eq(2).html();
			phoneNumber=$obj.parents("tr").find("td").eq(3).html();
			roles=$obj.parents("tr").find("td").eq(4).html();
			$currentTr=$obj.parents("tr");
			if(answer==1){ 
			window.location.href = "adminMod.action"; //转到处理页面 
				//window.location.reload(); 刷新父窗口 
				//winow.location.reload(true); 

			} 
			} 
			*/
		//修改赋值
		function refreshRow(val0,val1,val2,val3){
			$currentTr.find("td").eq(0).html(val0);
			$currentTr.find("td").eq(1).html(val1);
			$currentTr.find("td").eq(2).html(val2);
			$currentTr.find("td").eq(3).html(val3);
		}
		
		function select(){
			var id = $("#role").val();
			if(id==1){
				$("#ms").css("visibility","hidden");
			}else{
				$("#ms").css("visibility","visible");
				}
			}
	</script>
	<script type="text/javascript">
		$(function(){
			//$(".registerform").Validform();  //就这一行代码！;
	
			$(".registerform").Validform({
				tiptype:2
			});
		});
	</script>
	
</body>
</html>
